package gui.components.JXComboBox.JXComboRenderers;

import javax.swing.*;
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
import java.util.HashMap;
import java.util.Vector;

/**
 * Date: 12.10.2005
 * Time: 19:18:54
 */
public class JXListRenderer extends JList implements ListCellRenderer, iJXCellRenderer{

    public static final int renderClass = 0;
    public int getRenderClass(){
        return renderClass;
    }
    private HashMap<Integer,Color> rows = new HashMap<Integer,Color>();
    private Color defColor = new Color(255,255,255);

    public JXListRenderer() {
        setOpaque(true);
        setForeground(UIManager.getColor("TableHeader.foreground"));
        setBackground(UIManager.getColor("TableHeader.background"));
        setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    }

    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        setFont(list.getFont());
        String str = (value == null) ? "" : value.toString();
        BufferedReader br = new BufferedReader(new StringReader(str));
        if (rows.containsKey(index)){
            setBackground(rows.get(index));
            System.out.println("action");
        }else{setBackground(defColor);}
        if (isSelected){this.setBackground(new Color(89,255,89));}
        String line;
        Vector v = new Vector();
        try {
            while ((line = br.readLine()) != null) {
                v.addElement(line);
                line.getBytes();
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        setListData(v);
        return this;
    }


    public void addAlignment(int align) {}
    public void removeAlignment() {}

    public void addMarkRow(Integer pos, Color color){
        rows.put(pos,color);
    }

    public void removeMarkRow(int pos){
        rows.remove(pos);
    }
}
